(*
This file is part of the Lustre reader

* Copyright (c) 2010, Nicola Camuffo.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of Nicola Camuffo, nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)


(* aliases *)
type _sym = string
type _id = int

(* data types *)
type _type =
	T_NONE
	
  | T_INT
  | T_REAL
  | T_BOOL
  | T_TUPLE of _type list
  | T_STRUCT of (_sym * _type) list
  | T_ENUM of _sym list
  | T_LIST of _type list
  | T_NAMED of _id

	(* lv6 has indefinite entities (e.g type t; const c:t): how does parser do type checking? in this way 
		 type checking is done in the steps *)
  | T_TOCHECK

  (* since the parser doesn't do type checking, expressions evaluation is impossible: when i create an array, it's 
     impossible to transform it to tuple (i don't know length) *)
  | T_ARRAY of _type * _typed_expression

(* expressions *)
and _expression =
	E_NONE
	
  | E_BOOL of bool
  | E_INT of int
  | E_REAL of float

  | E_VAR of _id
  | E_CONST of _id

  | E_AND of _typed_expression * _typed_expression
  | E_OR of _typed_expression * _typed_expression
  | E_XOR of _typed_expression * _typed_expression
  | E_IMPL of _typed_expression * _typed_expression
  | E_NOT of _typed_expression

  | E_ITE of _typed_expression * _typed_expression * _typed_expression
  | E_WTE of _typed_expression * _typed_expression * _typed_expression

  | E_EQ of _typed_expression * _typed_expression
  | E_NEQ of _typed_expression * _typed_expression
  | E_LT of _typed_expression * _typed_expression
  | E_LTE of _typed_expression * _typed_expression
  | E_GT of _typed_expression * _typed_expression
  | E_GTE of _typed_expression * _typed_expression
  | E_PLUS of _typed_expression * _typed_expression
  | E_MINUS of _typed_expression * _typed_expression
  | E_UMINUS of _typed_expression
  | E_MULT of _typed_expression * _typed_expression
  | E_DIV of _typed_expression * _typed_expression
  | E_INTDIV of _typed_expression * _typed_expression
  | E_MOD of _typed_expression * _typed_expression

  | E_NOR of _typed_expression list
  | E_EXCL of _typed_expression list

  | E_COERCE_TO_INT of _typed_expression
  | E_COERCE_TO_REAL of _typed_expression
  | E_COERCE_TO_BOOL of _typed_expression

  | E_PRE of _typed_expression
  | E_FOLLOWEDBY of _typed_expression * _typed_expression

  | E_WHEN of _typed_expression * _typed_expression
  | E_CURRENT of _typed_expression

  | E_TUPLE of _typed_expression list
  | E_STRUCT of (_sym * _typed_expression) list
  | E_LIST of _typed_expression list

  | E_ENUMSEL of _id * _sym (* type id, field name *)
  | E_STRUCTSEL of _typed_expression * _sym (* struct, field name *)
  | E_TUPLESEL of _typed_expression * _typed_expression * _typed_expression * _typed_expression (* tuple, inf, sup, step *)

  | E_NODE of _id * _typed_expression list (* node id, param list*)
  | E_OUTVAR of _typed_expression * _id (* node, var *)

  (* SCADE *)
(* | E_CASE of (_typed_expression * _typed_expression) list * _typed_expression *)
  | E_CONDACT of _typed_expression * _typed_expression * _typed_expression
  | E_FBY of _typed_expression * int * _typed_expression (* expr, num steps, init value *)

  (* see T_ARRAY constructor *)
  | E_ARRAY of _typed_expression * _typed_expression

and _typed_expression = _expression * _type

(* left hand sides *)
type _lhs =
	L_VAR of _id
	| L_STRUCTSEL of _typed_lhs * _sym
	| L_TUPLESEL of _typed_lhs * _typed_expression * _typed_expression * _typed_expression
	| L_LIST of _typed_lhs list

and _typed_lhs = _lhs * _type
